package main

import (
	"log"
	"os"

	"pay_service/internal/db"
	"pay_service/internal/dotenv"
)

func main() {
	dotenv.Init()
	db.Init()
	objs := []string{"pay_order"}
	for _, s := range objs {
		path := "./sql/seed/" + s + ".sql"
		sqlBytes, err := os.ReadFile(path)
		if err != nil {
			log.Fatalf("ERROR: can not read %s: %v", s, err)
		}

		sqlStr := string(sqlBytes)

		// 执行 SQL 语句
		if err := db.DB.Exec(sqlStr).Error; err != nil {
			log.Fatalf("ERROR: can not create %s: %v", s, err)
		}
	}

	log.Println("建表成功")
}
